package com.zhuss.core.role;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;

import com.zhuss.bean.bo.core.role.CreateRoleBo;
import com.zhuss.bean.bo.core.role.DeleteRoleBo;
import com.zhuss.bean.bo.core.role.RolePermissionBindBo;
import com.zhuss.bean.bo.core.role.RoleUserBindBo;
import com.zhuss.bean.bo.core.role.StartRoleBo;
import com.zhuss.bean.bo.core.role.StopRoleBo;
import com.zhuss.bean.bo.core.role.UpdateRoleBo;
import com.zhuss.common.OperateService;
import com.zhuss.common.Processor;
import com.zhuss.exception.AabException;

/**
 * 角色操作service（基本操作）
 * @author zhushanshuo
 * @Date 2019-12-13 15:59
 *
 */
@Component("roleOperateService")
public class RoleOperateService implements OperateService<Void, Object> {
	
	@Autowired
	@Qualifier("roleCreate")
	private Processor<Object, CreateRoleBo> roleCreate;
	
	@Autowired
	@Qualifier("roleUpdate")
	private Processor<Object, UpdateRoleBo> roleUpdate;
	
	@Autowired
	@Qualifier("roleStart")
	private Processor<Object, StartRoleBo> roleStart;
	
	@Autowired
	@Qualifier("roleStop")
	private Processor<Object, StopRoleBo> roleStop;
	
	@Autowired
	@Qualifier("rolePermissionBind")
	private Processor<Object, RolePermissionBindBo> rolePermissionBind;
	
	@Autowired
	@Qualifier("roleUserBind")
	private Processor<Object, RoleUserBindBo> roleUserBind;
	
	@Autowired
	@Qualifier("roleDelete")
	private Processor<Object, DeleteRoleBo> roleDelete;
	
	/**
	 * 创建
	 */
	@Override
    @Transactional(rollbackFor = Exception.class)
	public Void create(Object param) throws AabException {
		
		CreateRoleBo bo = (CreateRoleBo) param;
		
		roleCreate.process(bo);
		
		return null;
	}
    
	/**
	 * 修改
	 */
	@Override
    @Transactional(rollbackFor = Exception.class)
    public Void update(Object param) throws AabException {
    	
		UpdateRoleBo bo = (UpdateRoleBo) param;
		
		roleUpdate.process(bo);
		
    	return null;
    }
	
	/**
	 * 删除
	 */
	@Override
	@Transactional(rollbackFor = Exception.class)
	public Void delete(Object param) throws AabException {
		
		DeleteRoleBo bo = (DeleteRoleBo) param;
		
		roleDelete.process(bo);
		
		return null;
	}
	
	/**
	 * 启用角色
	 */
	@Transactional(rollbackFor = Exception.class)
	protected Void start(Object param) throws AabException {
		
		StartRoleBo bo = (StartRoleBo) param;
		
		roleStart.process(bo);
		
		return null;
	}
	
	/**
	 * 停用角色
	 */
	@Transactional(rollbackFor = Exception.class)
	protected Void stop(Object param) throws AabException {
		
		StopRoleBo bo = (StopRoleBo) param;
		
		roleStop.process(bo);
		
		return null;
	}
	
	/**
	 * 给角色绑定权限
	 */
	@Transactional(rollbackFor = Exception.class)
	public Void rolePermissionBind(Object param) throws AabException {
		
		RolePermissionBindBo bo = (RolePermissionBindBo) param;
		
		rolePermissionBind.process(bo);
		
		return null;
	}
	
	/**
	 * 给角色绑定用户
	 */
	@Transactional(rollbackFor = Exception.class)
	public Void roleUserBind(Object param) throws AabException {
		
		RoleUserBindBo bo = (RoleUserBindBo) param;
		
		roleUserBind.process(bo);
		
		return null;
	}
	
}

